let express = require("express");

let fs = require("fs");

let router = express.Router();

router.use(express.urlencoded({extended:false}));

let ejs = require("ejs");

// router.use(express.static(__dirname + "/static"));


router.get("/login", (req, res) => {
    res.render("login.html")
})

router.post("/login",(req,res)=>{
    let persons = fs.readFileSync(__dirname + "/persons.json", "utf8");
    persons = JSON.parse(persons);
    let {tel,pass} = req.body;
    let users = persons.find((item) => {
        //console.log(item);
        return tel == item.username && pass == item.password;
    })
    if(users){
        res.send("登录成功");
    }else{
        res.send("登录失败");
    }
})

module.exports = router;